# makefile
# written by yaolunlun@sina.com
# version 1.0
# last update 09/14/2016

TOP_DIR		:= $(CURDIR)/../
include $(TOP_DIR)/Env.make

TARGET		:= aliiot
SRCS		:= aliiot.c shm_data.c
OBJS		:= $(SRCS:.c=.o)

CFLAGS		:= -g -Wall -std=gnu99 \
				-I./ \
				-I../include/ \
				-I../aliiot_sdk/src/mqtt/MQTTClient-C/src/ \
				-I../aliiot_sdk/src/mqtt/MQTTPacket/src/ \
				-I../aliiot_sdk/platform/linux/inc/ \
				-I../aliiot_sdk/public_libs/mbedtls/include/mbedtls/ \
				-I../aliiot_sdk/common/inc/ \
				-I../aliiot_sdk/include/mqtt/

LDFLAGS		:= -lpthread -lm -lcurl \
				../aliiot_sdk/libiotsdk.a \
				libcjson/libcjson.a \
				libsha1/libsha1.a


all: $(TARGET)

$(TARGET): libsha1 libcjson $(OBJS)
	$(ECHO)echo LD $@
	$(ECHO)$(CC) $(CFLAGS) -o $(TARGET) $(OBJS) $(LDFLAGS)

libcjson:
	$(MAKE) -C libcjson/

libcjson-clean:
	$(MAKE) clean -C libcjson/

libsha1:
	$(MAKE) -C libsha1/

libsha1-clean:
	$(MAKE) clean -C libsha1/

aliiot-demo:
	$(MAKE) -C ../aliiot_sdk/

aliiot-demo-clean:
	$(MAKE) clean -C ../aliiot_sdk/

%.o: %.c
	$(ECHO)echo CC $@
	$(ECHO)$(CC) $(CFLAGS) -c -o $@ $<

install:
	$(MKDIR) $(TOP_DIR)/bin/
	$(INSTALL) $(TARGET) $(TOP_DIR)/bin/

clean:
	$(RM) *.o
	$(RM) $(TARGET)

	
.PHONY: all clean aliiot-demo-clean aliiot-demo libcjson libcjson-clean libsha1 libsha1-clean

